<?php

namespace Modules\Admin\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class AdminUserRequest extends FormRequest
{
    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        //应该获取到当前验证规则被使用的方法访问的路由规则中的参数
        $roleid = $this->route('adminuser');
        return [
            //第一个参数unique验证方法可以用来验证某个字段是否在某个指定的表中是否唯一,如果唯一,就通过,如果不唯一,会有错误信息出来
            'name' => 'required|unique:admins,name,'.$roleid,
            'nickname' => 'required|unique:admins,nickname,'.$roleid,
            'password' => 'nullable|between:3,15',
        ];
    }

    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }
}
